﻿using Direct.IDAL.Manager.UserCenter;
using DirectSell.Common.Filter;
using DirectSell.Common.Http;
using DirectSell.Common.InvokeInterface;
using DirectSell.Common.Page;
using DirectSell.Common.Url;
using DirectSell.Model.Query;
using DirectSell.Model.User;
using Microsoft.Practices.Unity;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace DirectSell.WebLayer.Areas.Manager.Controllers
{
    /// <summary>
    /// 已开通用户
    /// </summary>
    public class MemberListController : Controller
    {
        #region 注入
        [Dependency]
        protected IMemberListRepository _repository { get; set; }
        #endregion

        #region 首页
        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        [ManagerFilter(IsCheck =true)]
        public async Task<ActionResult> Index(BaseCondition condition)
        {
            condition.startTime = Request["startTime"];

            condition.endTime = Request["endTime"];

            var list = await _repository.QueryList(condition);

            if (Request.IsAjaxRequest())
                return PartialView("_AjaxSearchPost", list);

            return View(list);
        }
        #endregion

        #region 修改资料页面
        /// <summary>
        /// 修改资料
        /// </summary>
        /// <param name="usercode"></param>
        /// <returns></returns>
        public ActionResult Edit(string usercode)
        {
            var info = _repository.GetUserInfo(usercode);
            return PartialView(info);
        }
        #endregion

        #region 修改资料操作
        /// <summary>
        /// 修改资料操作
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public JsonResult EditMessage(UserInforMationDetails req)
        {
            return Json(_repository.EditMessage(req));
        }
        #endregion

        #region 用戶信息
        /// <summary>
        /// 用戶信息
        /// </summary>
        /// <param name="usercode"></param>
        /// <returns></returns>
        public ActionResult MemberInfo(string usercode)
        {
            var info =  _repository.GetUserInfo(usercode);
            return PartialView(info);

        }
        #endregion

        #region 冻结会员
        /// <summary>
        /// 冻结会员
        /// </summary>
        /// <param name="userCode"></param>
        /// <returns></returns>
        public bool Forzen(string userCode)
        {
            return _repository.FrozenUser(userCode);
        }
        #endregion

        #region 启用会员
        /// <summary>
        /// 启用会员
        /// </summary>
        /// <param name="userCode"></param>
        /// <returns></returns>
        public bool Enable(string userCode)
        {
            return _repository.EnableUser(userCode);
        }
        #endregion

    }
}